package br.com.projeto.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import br.com.projeto.model.Jogo;

import com.tbm.megasena.R;

public class ListarJogosModificadosAdapter extends BaseAdapter {

	private List<Jogo> games;
	private ViewHolder holder;
	private LayoutInflater layoutInflater;

	public ListarJogosModificadosAdapter(Context context, List<Jogo> listGames) {
		this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.games = listGames;
	}

	private class ViewHolder {
		private TextView txtNumber1;
		private TextView txtNumber2;
		private TextView txtNumber3;
		private TextView txtNumber4;
		private TextView txtNumber5;
		private TextView txtNumber6;
		private Button btnRemove;
		private Button btnUpdate;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (view == null) {
			view = layoutInflater.inflate(R.layout.salvar_item, null);
			holder = new ViewHolder();

			holder.txtNumber1 = (TextView) view.findViewById(R.id.txtNumber1);
			holder.txtNumber2 = (TextView) view.findViewById(R.id.txtNumber2);
			holder.txtNumber3 = (TextView) view.findViewById(R.id.txtNumber3);
			holder.txtNumber4 = (TextView) view.findViewById(R.id.txtNumber4);
			holder.txtNumber5 = (TextView) view.findViewById(R.id.txtNumber5);
			holder.txtNumber6 = (TextView) view.findViewById(R.id.txtNumber6);
			
			holder.btnRemove = (Button) view.findViewById(R.id.btnRemove);
			holder.btnUpdate = (Button) view.findViewById(R.id.btnUpdate);
			
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		
		Jogo game = games.get(position);
		
		holder.txtNumber1.setText(game.getNumero1());
		holder.txtNumber2.setText(game.getNumero2());
		holder.txtNumber3.setText(game.getNumero3());
		holder.txtNumber4.setText(game.getNumero4());
		holder.txtNumber5.setText(game.getNumero5());
		holder.txtNumber6.setText(game.getNumero6());
		
		holder.btnRemove.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
			}
		});
		
		holder.btnUpdate.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
			}
		});
		
		return view;
	}

	@Override
	public int getCount() {
		return games.size();
	}

	@Override
	public Object getItem(int position) {
		return games.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

}
